package com.my.screenadapter.sql;

import android.database.Cursor;
import android.util.Log;

/**
 * Created by zhangyingjie on 2019-09-05
 *
 * @function
 */
public class CursorUtil {

    private static final String TAG = "CursorUtil";
    public static void foreachCursor(Cursor cursor) {
        Log.i(TAG, "foreachCursor: ");
        if (cursor != null) {
            Log.i(TAG, "foreachCursor: count "+cursor.getCount());
            Log.i(TAG, "foreachCursor: count moveToFirst "+cursor.moveToFirst());
        }
        if (cursor!=null && cursor.getCount()>0 && cursor.moveToFirst()) {
            int index =0;
            int columnCount = cursor.getColumnCount();
            do{
                for (int i = 0; i < columnCount; i++) {
                Log.i(TAG, "run: cursor row"+index+" column"+i +" "+cursor.getString(i));
                 }
                index++;
                //取出数据,调用cursor.getInt/getString等方法
            }while(cursor.moveToNext());
        }

    }


    public static Object[] getObjectData(String result, String msg) {
        Log.i(TAG, " cusor --------"+result+" "+msg);

//      测试样例
//        String str = "{\n" +
//                "            \"visitorName\": \"张英杰\",\n" +
//                "            \"attendeeCompany\": \"蜂盒\",\n" +
//                "            \"visitStartTime\": \"2019-08-15 10:30\",\n" +
//                "            \"username\": \"张英杰\"\n" +
//                "        }";
//
//        LinkedList<CheckAPIResponse> checkAPIResponses = new LinkedList<>();
//        checkAPIResponses.add( MyApplication.getGson().fromJson(str,CheckAPIResponse.class));
//        new PrintClient(MyApplication.getInstance().getApplicationContext(),checkAPIResponses);

        return new Object[]{"{" +
                "'result': " + result + "," +
                "'message':'" + msg + "'" +
                "}"};
    }
}
